package com.ordertracker;

import com.ordertracker.client.exception.ClientContextInitializationException;
import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.jersey.api.json.JSONJAXBContext;
import com.sun.jersey.api.json.JSONMarshaller;

import javax.xml.bind.Marshaller;
import javax.xml.bind.PropertyException;

/**
 * Description of class.
 * Created 2/6/13 11:26 AM
 *
 * @author andrey.rodin@playtech.com
 */

public final class ClientJAXBContext {
    private static final String ENTITY_PACKAGE = "com.ordertracker";

    private static JSONMarshaller jsonMarshaller;
    private static JSONJAXBContext context;

    private static final ClientJAXBContext instance = new ClientJAXBContext();

    private ClientJAXBContext() {
        try {
            context = new JSONJAXBContext(JSONConfiguration.mapped().build(), ENTITY_PACKAGE);
            jsonMarshaller = context.createJSONMarshaller();
            jsonMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        } catch (Exception e) {
            throw new ClientContextInitializationException(e);
        }
    }

    public static ClientJAXBContext getInstance() {
        return instance;
    }

    public static JSONJAXBContext getContext() {
        return context;
    }

    public static JSONMarshaller getJsonMarshaller() {
        return jsonMarshaller;
    }
}
